<template xmlns:el-col="http://www.w3.org/1999/html">
    <div style=" user-select: none;">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-cascades"></i> 患者信息
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-input v-model="query.ptNm" placeholder="姓名" class="handle-input mr10"
                          @keyup.enter.native="handleSearch" style="width: 16%"></el-input>
                <el-input v-model="query.createdAccount" placeholder="主治医生" class="handle-input mr10"
                          @keyup.enter.native="handleSearch" style="width: 16%"></el-input>
                <el-select v-model="query.ptSex" placeholder="性别" class="handle-select mr10"
                           @keyup.enter.native="handleSearch" style="width: 16%">
                    <el-option key="00" label="男" value="00"></el-option>
                    <el-option key="01" label="女" value="01"></el-option>
                </el-select>
                <el-button type="primary" icon="el-icon-search" @click.native="handleSearch">搜索</el-button>
                <el-button type="el-button" icon="el-icon-delete" @click.native="handleReset">重置</el-button>
            </div>
            <el-table
                    :data="tableData"
                    border
                    class="table"
                    ref="multipleTable"
                    header-cell-class-name="table-header"
                    @selection-change="handleSelectionChange"
            >
                <el-table-column prop="ptId" label="患者编号" align="center"></el-table-column>
                <el-table-column prop="ptNm" label="姓名" align="center"></el-table-column>
                <el-table-column prop="ptSexText" label="性别" align="center"></el-table-column>
                <el-table-column prop="ptAge" label="年龄" align="center"></el-table-column>
                <el-table-column prop="ptHeight" label="身高/cm" align="center"></el-table-column>
                <el-table-column prop="createdAccount" label="主治医生" align="center"></el-table-column>
                <el-table-column prop="createdTime" label="创建时间" align="center"></el-table-column>
                <el-table-column label="操作" align="center" >
                    <template slot-scope="scope">
                        <el-button style="font-size: 20px"
                                   type="text"
                                   icon="el-icon-edit"
                                   @click.native="handleEdit(scope.$index, scope.row)"
                        >查看
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                        background
                        layout="total, prev, pager, next"
                        :current-page="query.pageIndex"
                        :page-size="query.pageSize"
                        :total="pageTotal"
                        @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>

        <!-- 编辑弹出框 -->
        <el-dialog title="查看" :visible.sync="editVisible" width="70%" :before-close="editColse">
            <el-form ref="form" :model="form"  label-width="100px">
                <el-row>
                    <el-col :span="10">
                        <el-form-item label="患者ID" prop="ptId">
                            <el-input readonly v-model="form.ptId" style="width: 100%"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="10">
                        <el-form-item label="姓名" prop="ptNm">
                            <el-input readonly v-model="form.ptNm" style="width: 100%"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="10">
                        <el-form-item label="性别" prop="ptSex">
                            <el-select disabled v-model="form.ptSex" placeholder="请选择性别" style="width: 100%">
                                <el-option key="00" label="男" value="00"></el-option>
                                <el-option key="01" label="女" value="01"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="10">
                        <el-form-item label="手机号" prop="ptPhone">
                            <el-input readonly v-model="form.ptPhone" style="width: 100%;"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="10">
                        <el-form-item label="患者身高" prop="ptHeight">
                            <el-input readonly type="number" v-model="form.ptHeight" :min="1" placeholder="单位/cm"
                                      style="width: 100%;" ></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="10">
                        <el-form-item label="证件类型" prop="ptCerTp">
                            <el-select disabled v-model="form.ptCerTp" style="width: 100%">
                                <el-option key="00" label="身份证" value="00"></el-option>
                                <el-option key="01" label="护照" value="01"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="10">
                        <el-form-item label="证件号码" prop="ptCerNo">
                            <el-input readonly v-model="form.ptCerNo" style="width: 100%"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="10">
                        <el-form-item label="出生日期" prop="ptBirth">
                            <el-date-picker style="width: 100%;" readonly
                                            v-model="form.ptBirth"
                                            type="date"
                                            placeholder="选择日期"
                                            value-format="yyyy-MM-dd"
                                           >
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="10">
                        <el-form-item label="年龄" prop="ptAge">
                            <el-input readonly type="number" ref="inputFormAge" v-model="form.ptAge" style="width: 100%;"
                                      :min="7"  readonly></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="20">
                        <el-form-item label="家庭住址" prop="ptAddres">
                            <el-input readonly v-model="form.ptAddres" style="width: 100%;"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="editColse">关闭</el-button>
            </span>
        </el-dialog>

    </div>
</template>

<script>
    import {patientData,} from '../../../api/matting/patient';
    export default {
        name: 'patient',
        data() {
            return {
                query: {//检索条件
                    ptNm: '',
                    createdAccount: '',
                    ptSex: '',
                    /*userAcct:localStorage.getItem('ms_userAcct'),*/
                    pageIndex: 1,
                    pageSize: 10
                },
                tableData: [],
                multipleSelection: [],
                editVisible: false,
                prescriptionVisible: false,
                pageTotal: 0,
                roleIds: localStorage.getItem('ms_roleIds'),
                form: {
                    ptId: '',
                    ptNm: '',
                    ptSex: '',
                    ptCerTp: '',
                    ptCerNo: '',
                    ptBirth: '',
                    ptAge: '',
                    ptPhone: '',
                    ptDoctor: '',
                    ptAddres: '',
                    ptHeight: '',
                },
                idx: -1,
                id: -1,
                total: 1,
            };
        },

        created() {
            this.getData();
        },
        methods: {
            // 获取 easy-mock 的模拟数据
            getData() {
                patientData(this.query).then(res => {
                    this.tableData = res.data;
                    this.pageTotal = res.total;
                });
            },
            // 触发搜索按钮
            handleSearch() {
                this.$set(this.query, 'pageIndex', 1);
                this.getData();
            },
            // 触发重置按钮
            handleReset() {
                this.query.ptNm = "";
                this.query.createdAccount = "";
                this.query.ptSex = "";
                this.getData();
            },
            // 多选操作
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            seeColse() {
                this.$confirm('确认关闭？', '提示', {
                    type: 'warning'
                })
                    .then(() => {
                        this.seeVisible = false;
                        this.getData();
                    })
                    .catch(() => {
                        this.$message({
                            message: '已取消操作'
                        });
                    });

            },
            // 编辑操作
            handleEdit(index, row) {
                this.idx = index;
                this.form = row;
                this.editVisible = true;
            },
            editColse() {//关闭编辑弹出框
                this.form = {};
                this.getData();
                this.editVisible = false;
            },
            // 分页导航
            handlePageChange(val) {
                this.$set(this.query, 'pageIndex', val);
                this.getData();
            },
        }
    };
</script>
<style scoped>
    .handle-box {
        margin-bottom: 20px;
    }

    .handle-select {
        width: 120px;
    }

    .handle-input {
        width: 300px;
        display: inline-block;
    }

    .table {
        width: 100%;
        font-size: 14px;
    }

    .red {
        color: #ff0000;
    }

    .mr10 {
        margin-right: 10px;
    }

    .schart {
        width: 550px;
        height: 300px;
    }

    .content-title {
        clear: both;
        font-weight: 400;
        line-height: 50px;
        margin: 10px 0;
        font-size: 22px;
        color: #1f2f3d;
    }
</style>
